package ooday03;
//引用类型数组的演示
public class RefArrayDemo {
    public static void main(String[] args) {
        //声明Dog型数组dogs，包含3个元素，每个元素都是Dog型，默认值为null
        Dog[] dogs = new Dog[3];
        dogs[0] = new Dog("小黑",3,"黑");
        dogs[1] = new Dog("小白",4,"白");
        dogs[2] = new Dog("小灰",5,"灰");
        dogs[2].age=6;                          //修改第三只狗狗的年龄
        for (int i=0;i< dogs.length;i++){       //遍历dogs数组
            System.out.println(dogs[i].name);   //输出每只狗狗的名字
            dogs[i].eat();                      //每只狗狗吃饭
        }
        System.out.println("--------------------------------------");
        //声明Chick型数组chicks，包含3个元素，每个元素都是Chick型，默认值为null
        Chick[] chicks = new Chick[2];
        chicks[0] = new Chick("大花",2,"花");
        chicks[1] = new Chick("小花",2,"花");
        for (int i=0;i< chicks.length;i++){
            System.out.println(chicks[i].name);
            chicks[i].eat();
        }
        System.out.println("--------------------------------------");
        //声明Fish型数组fish，包含3个元素，每个元素都是Fish型，默认值为null
        Fish[] fish = new Fish[2];
        fish[0] = new Fish("小金",2,"金");
        fish[1] = new Fish("大金",3,"金");
        for (int i=0;i< fish.length;i++){
            System.out.println(fish[i].name);
            fish[i].eat();
        }
    }
}
